using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TaskMaster
{
    /// <summary>
    /// Form for editing the properties of a task.
    /// </summary>
    public partial class TaskParametersUI : Form
    {
        Task newTask;

        public TaskParametersUI()
        {
            newTask = new Task();
            InitializeComponent();
        }

        public TaskParametersUI(Task initializerTask)
        {
            InitializeComponent();
            newTask = initializerTask;
            textBox_Name.Text = newTask.TaskName;
            textBox_description.Text = newTask.TaskDescription;

            StringBuilder tagString = new StringBuilder();
            foreach (string tag in newTask.Tags)
            {
                tagString.Append(tag + ",");
            }
            // Remove extra comma at end.
            tagString.Remove(tagString.Length - 1, 1);
            textBox_Tags.Text = tagString.ToString();
        }

        private void button_ok_Click(object sender, EventArgs e)
        {
            newTask.TaskName = textBox_Name.Text;
            newTask.TaskDescription = textBox_description.Text;
            newTask.Tags.Clear();

            string[] tags = textBox_Tags.Text.Split(new char[] { ',' });

            foreach (string tag in tags)
            {
                newTask.Tags.Add(tag);
            }

            DialogResult = DialogResult.OK;
        }

        // Properties

        public Task Task
        {
            get { return newTask; }
        }

        private void button_cancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}